<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>百商汇</title>
	<meta name="viewport" content="initial-scale = 1.0,maximum-scale = 1.0,minimum-scale = 1.0,user-scalable = no,width = device-width">
	<meta name="format-detection" content="telephone=no" />
	<link rel="stylesheet" type="text/css" href="../csses/bankCard.css">
</head>
<body>
	<div class="bankCard_title">
		银行卡
		<img src="../image/back.png" onclick="goBack()" class="back">
		<a href="./addCard.html" data-ajax='false'>
			<img src="../image/addCard.png">
		</a>
	</div>
	<div class="null"></div>
	<div class="bankCard_box">
		
	</div>
	<div id="remindBox"></div>
	<script type="text/javascript" src="../lib/flexible.js"></script>
	<script type="text/javascript" src="../lib/jquery-1.10.1.min.js"></script>
	<script type="text/javascript" src="../lib/jquery.mobile-1.4.5.min.js"></script>
	<script type="text/javascript">
		function goBack(){
			window.history.back();
		}

		function remind(message){
			$('#remindBox').css('display','block').text(message);
			setTimeout(function(){
				$('#remindBox').css('display','none');
			},1500);
		}

		$.ajax({
			type : 'post',
			url : '/api/v1/bank/myCardList',
			data : {
				paramStr : "{'userName':'" + sessionStorage.userName + "','token':'" + sessionStorage.token + "'}"
			},
			dataType : 'json',
			timeout : 10000,
			success : function (data) {
				if(data.code == 200){
					var obj = JSON.parse(data.data);
					var cardList = obj.myCardList;
					sessionStorage.myCardList = obj.myCardList;
					var $ul = $('<ul></ul>').appendTo($('.bankCard_box'));
					for(var i = 0; i < cardList.length; i++){
						var $li = $('<li></li>').appendTo($ul).attr('id',cardList[i].id);
						var $img = $('<img/>').attr('src',cardList[i].img).appendTo($li);
						var $div = $('<div></div>').appendTo($li);
						var $p1 = $('<p></p>').text(cardList[i].bank_name).appendTo($div);
						var $p2 = $('<p></p>').text(cardList[i].bank_card).appendTo($div);
						$('<span></span>').text('删除').appendTo($li);
					}

					$('li').on('swipeleft',function(event){
						event.preventDefault();
						$(this).addClass('animation1').removeClass('animation2').siblings('li').removeClass('animation1').removeClass('animation2');
						$(this).find('span').on('click',function(event){
							event.preventDefault();
							var $bankCardId = $(this).parent().attr('id');
							$.ajax({
								type : 'post',
								url : '/api/v1/bank/delete',
								data : {
									paramStr : "{'userName':'" + sessionStorage.userName + "','token':'" + sessionStorage.token + "','bankCardId':'" + $bankCardId + "'}"
								},
								dataType : 'json',
								timeout : 10000,
								success : function (data) {
									remind(data.message);
									setTimeout(function(){
										window.location.href = '../index1.html#!/personal';
									},1500)
									
									// if(data.code == 200){
									// 	$(this).parent().animate({
									// 		height : '0'
									// 	},300,function(){
									// 		$(this).remove();
									// 	});
									// }
								},
								error : function (xhr,type,errorThrown) {
									// alert('未知错误');
								}
							});

						});
					});

					$('li').on('swiperight',function(event){
						event.preventDefault();
						$(this).removeClass('animation1').addClass('animation2');
					});
				}
			},
			error : function (xhr,type,errorThrown) {
				// alert('未知错误');
			}
		});
	</script>
</body>
</html>